package scala.maven;

import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;

import java.io.File;
import java.util.List;

/**
 * Compile Scala source into test-classes.  Corresponds roughly to testCompile
 * in maven-compiler-plugin
 *
 * @author <a href="ryan@darksleep.com">Ryan Daum</a>
 * @goal testCompile
 * @requiresDependencyResolution test
 * @phase process-test-sources
 * @description Scala Maven Plugin
 */
public class ScalaTestCompileMojo extends ScalaMojo {

    /**
     * Set this to 'true' to bypass unit tests entirely.
     * Its use is NOT RECOMMENDED, but quite convenient on occasion.
     *
     * @parameter expression="${maven.test.skip}"
     */
    protected boolean skip;

    /**
     * @parameter expression="${project.build.testOutputDirectory}
     */
    protected File testOutputDir;

    /**
     * @parameter default-value="src/test/scala"
     */
    protected File testSourceDir;

    /**
     * Project test classpath.
     *
     * @parameter expression="${project.testClasspathElements}"
     * @required
     * @readonly
     */
    protected List<String> classpathElements;

    /**
     * @parameter default-value="false"
     */
    protected boolean uncheckedWarnings;

    /**
     * @parameter default-value="false"
     */
    protected boolean deprecationWarnings;

    /**
     * @paramater default-value="false"
     */
    protected boolean useFsc;

    public void execute() throws MojoExecutionException, MojoFailureException {
        if (skip) return;

        super.execute();

        performCompile(testOutputDir, testSourceDir, classpathElements, deprecationWarnings, uncheckedWarnings, useFsc);
    }
}
